<template>
  <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
    <component :is="detailComp" :detailList="detailList" :baseCollegeId="id" @refresh="refresh"></component>
		<div slot="footer" class="dialog-footer">
			<el-button type="success" :disabled="baseCollege && baseCollege.checkStatus == 1" @click="handlePassCheck">通过校验</el-button>
			<el-button type="primary" :disabled="baseCollege && baseCollege.checkStatus == 1 && baseCollege.status == 1" @click="handleToSummary">转汇总表</el-button>
			<el-button @click="cancel">关 闭</el-button>
		</div>
  </el-dialog>
</template>

<script>
import { getBaseCollegeDetail, passCheck, toSummary } from "@/api/statistics/baseCollege";

import Equipment from "../statisticsEquipment/index.vue"
import Laboratory from "../statisticsLaboratory/index.vue"
import Person from "../statisticsPerson/index.vue"
import Project from "../statisticsProject/index.vue"

export default {
  name: "StatisticsDetail",
  components: {
    Equipment,
    Laboratory,
    Person,
    Project
  },
	props: {
		typeList: Array,
		baseId: Number,
		collegeList: Array
	},
  data() {
    return {
			open: false,
      // 弹出层标题
      title: "统计详情",
      id: null,
      detailComp: null,
      baseCollege: null,
      detailList: []
    };
  },
  created() {
  },
  methods: {
    handleShow(id) {
      this.id = id;
      getBaseCollegeDetail(id).then(response => {
        this.baseCollege = response.data;
        this.detailList = this.baseCollege.detailList;
        switch (this.baseCollege.type) {
          case "1":
            this.detailComp = Equipment
            break;
          case "2":
            this.detailComp = Project
            break;
          case "3":
            this.detailComp = Person
            break;
          case "4":
            this.detailComp = Laboratory
            break;
        }
        this.open = true
      });
    },
    // 取消按钮
    cancel() {
      this.open = false
    },
    handlePassCheck() {
      passCheck(this.baseCollege.id).then(response => {
        this.msgSuccess("通过校验成功");
        this.baseCollege.checkStatus = 1
      })
    },
    handleToSummary() {
      toSummary(this.baseCollege.id).then(response => {
        this.msgSuccess("转汇总表成功");
        this.baseCollege.status = 1
      })
    },
    refresh() {
      getBaseCollegeDetail(this.id).then(response => {
        this.baseCollege = response.data;
        this.detailList = this.baseCollege.detailList;
      });
    }
  }
};
</script>
